#include <QDebug>
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    m_pTcpSocket = new QTcpSocket();
    ui->lineeditIp->setText("42.192.22.128");
    ui->lineeditPort->setText("8000");
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_btnConnection_clicked()
{
    m_pTcpSocket->connectToHost(ui->lineeditIp->text(), ui->lineeditPort->text().toUShort());
    qDebug() << m_pTcpSocket->state();
}

void Widget::on_btnSend_clicked()
{
    qDebug() << m_pTcpSocket->state();
    QByteArray byteArray;
    byteArray.append(ui->texteditMsg->toPlainText());
    const char *pChatMsg = byteArray.data();
    qDebug() << m_pTcpSocket->write(pChatMsg, byteArray.size());
}
